import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  // 创建一个状态state：响应式数据
  const count = ref(0)
  // 利用computed组合式API对 state数据的二次封装
  const doubleCount = computed(() => count.value * 2)
  // 用函数实现对state数据的修改
  function increment() {
    count.value++
  }
  // 返回对象
  return { count, doubleCount, increment }
})